#include "console.h"

#pragma import(__use_no_semihosting)

void _sys_exit(int x)
{
	x = x;
}

void _ttywrch(int ch)
{
	ch = ch;
}

struct __FILE
{
	int handle;
};

FILE __stdout;

void debug_uart_init(void)
{
	rcu_periph_clock_enable(RCU_USART2);
	rcu_periph_clock_enable(RCU_GPIOB);
	gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
	gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_11);
	
	usart_baudrate_set(USART2, 115200);
	usart_parity_config(USART2, USART_PM_NONE);
	usart_word_length_set(USART2, USART_WL_8BIT);
	usart_stop_bit_set(USART2, USART_STB_1BIT);
	usart_transmit_config(USART2, USART_TRANSMIT_ENABLE);
	usart_receive_config(USART2, USART_RECEIVE_ENABLE);
	usart_enable(USART2);
}

int fputc(int ch, FILE *f)
{
	usart_data_transmit(USART2, (uint8_t)ch);
	while(RESET == usart_flag_get(USART2, USART_FLAG_TBE));
	return (ch);
}


